package com.kaiwukj.android.ufamily.mvp.ui.page.home.service;

import androidx.annotation.NonNull;

import com.kaiwukj.android.mcas.mvp.BasePresenter;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.helper.ServiceHelperResult;
import com.kaiwukj.android.ufamily.mvp.http.utils.RxUtils;
import com.kaiwukj.android.ufamily.mvp.ui.page.service.ServiceContract;

import javax.inject.Inject;

import io.reactivex.Observable;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;

public class ServicePresenter extends BasePresenter<ServiceContract.Model, ServiceContract.View> {

    @Inject
    RxErrorHandler mErrorHandler;

    @Inject
    public ServicePresenter(ServiceContract.Model model, ServiceContract.View view) {
        super(model, view);
    }

    public void fetchServiceGroup() {

        Observable.zip(mModel.whetherOwner(), mModel.fetchServiceGroup(), ServiceHelperResult::new)
                .compose(RxUtils.schedulerHelper())
                .subscribe(new ApiCallBack<ServiceHelperResult>() {
                    @Override
                    public void onSuccess(@NonNull ServiceHelperResult result) {
                        mRootView.onFetchServiceGroup(result);
                    }
                });

      /*  mModel.fetchServiceGroup()
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<List<ServiceGroupResult>>(mErrorHandler, mRootView) {
                    @Override
                    public void onSuccess(@NonNull List<ServiceGroupResult> result) {
                        mRootView.hideLoading();
                        mRootView.onFetchServiceGroup(result);
                    }
                });*/
    }

}
